package cn.iocoder.yudao.module.famous.doctor.controller.app.versioncontrol;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.famous.doctor.controller.admin.versioncontrol.vo.*;
import cn.iocoder.yudao.module.famous.doctor.convert.versioncontrol.VersionControlConvert;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.versioncontrol.VersionControlDO;
import cn.iocoder.yudao.module.famous.doctor.service.versioncontrol.VersionControlService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

@Tag(name = "用户 App - 版本控制")
@RestController
@RequestMapping("/famous.doctor/version-contro/app")
@Validated
public class AppVersionControlController {

    @Resource
    private VersionControlService versionControlService;

    @PostMapping("/create")
    @Operation(summary = "创建版本控制")
    public CommonResult<Long> createVersionControl(@Valid @RequestBody VersionControlCreateReqVO createReqVO) {
        return success(versionControlService.createVersionControl(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新版本控制")
    public CommonResult<Boolean> updateVersionControl(@Valid @RequestBody VersionControlUpdateReqVO updateReqVO) {
        versionControlService.updateVersionControl(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除版本控制")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteVersionControl(@RequestParam("id") Long id) {
        versionControlService.deleteVersionControl(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得版本控制")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<VersionControlRespVO> getVersionControl(@RequestParam("id") Long id) {
        VersionControlDO versionControl = versionControlService.getVersionControl(id);
        return success(VersionControlConvert.INSTANCE.convert(versionControl));
    }

    @GetMapping("/list")
    @Operation(summary = "获得版本控制列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<VersionControlRespVO>> getVersionControlList(@RequestParam("ids") Collection<Long> ids) {
        List<VersionControlDO> list = versionControlService.getVersionControlList(ids);
        return success(VersionControlConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得版本控制分页")
    public CommonResult<PageResult<VersionControlRespVO>> getVersionControlPage(@Valid VersionControlPageReqVO pageVO) {
        PageResult<VersionControlDO> pageResult = versionControlService.getVersionControlPage(pageVO);
        return success(VersionControlConvert.INSTANCE.convertPage(pageResult));
    }

}
